
## Working directory for replication
setwd("E:/finalidealreplication/")

## Load EDM ideal point models
library(edmideal)

## Load initial values for two-cutpoint model
## Generated from ideal point estimates from one-cutpoint model
load("init.twocut.R")

## Load signature matrix and sponsor IDs
mpinc98.v4 <- as.matrix(read.csv("mpinc98.v4.csv", row.names=1))
sponsorchar <- read.csv("sponsors.csv", row.names=1)
sponsor.vector98 <- sponsorchar[,1]

## Construct random starting values centered at initial values
set.seed(73457)
ideal.start1 <- ideal.start + rnorm(length(ideal.start), 0, .2)

## Run chain for 50000 iterations, saving every 50th iteration
test1sal <- NewIdealSliceUnfold(mpinc98.v4, sponsor.vector98, negative="Benn/Tony", burnin=0, 
			thin=50, sample=1000, initial.idealpoints =
                      	ideal.start1, verbose=100)

## Save results of first 50000 draws
save(test1sal, file="test1sal.RData") 

## Continue chain for 50000 additional iterations, saving every 50th iteraction
set.seed(524576)
test1sal2 <- NewIdealSliceUnfold(mpinc98.v4, sponsor.vector98, negative="Benn/Tony", burnin=0, 
			thin=50, sample=1000, 
                  initial.idealpoints = test1sal[[1]][1000,], 
                  initial.motion = test1sal[[3]][1000,], 
                  initial.propensity = test1sal[[2]][1000,], 
                  initial.salience = test1sal[[4]][1000,], verbose=100)

## Save results of next 50000 draws
save(test1sal2, file="test1sal2.RData") 


